<template>
  <!-- 法律法规 -->
  <view class="lawsAndRegulations">
    <view class="wrapper-content">
      <scroll-view
        scroll-y="true"
        @scrolltolower="scrollBottom"
        :style="[
          {
            height: '100%',
          },
        ]"
        v-if="dataSource.length"
      >
        <view
          class="wrapper-item"
          v-for="(v, i) in dataSource"
          :key="i"
          @click="urlHandle(v)"
        >
          <view class="itemList">
            <view class="line-hidden name"> {{ v.articleNo }} </view>
            <view style="margin-top: 7rpx">
              <u-icon name="arrow-right" color="#DEDCDC"></u-icon>
            </view>
          </view>
        </view>
        <view class="pageBottom" v-if="pageBottom">—— 到底了 ——</view>
      </scroll-view>
      <view v-if="!dataSource.length">
        <u-empty
          mode="list"
          text="暂无数据"
          icon="http://cdn.uviewui.com/uview/empty/list.png"
        >
        </u-empty>
      </view>
    </view>
  </view>
</template>

<script>
import { homePageDetail } from "@/api/messages.js";
import mixin from "@/utils/mixin.js";

export default {
  mixins: [mixin],
  data() {
    return {
      baseImgUrl: this.$baseImgUrl,
      dataSource: [],
      pageBottom: false,
      pageConfig: {
        pageNo: 1,
        pageSize: 20,
        total: 0,
      },
    };
  },
  onLoad(options) {
    this.options = options;
    uni.setNavigationBarTitle({
      title: `《${options.title}》`,
    });
  },
  onShow() {
    this.dataSource = [];
    this.pageConfig.pageNo = 1;
    this.getList();
  },
  methods: {
    scrollBottom() {
      let current = (this.pageConfig.pageNo += 1);
      let pages = Math.ceil(this.pageConfig.total / this.pageConfig.pageSize);
      if (current <= pages) {
        this.getList();
      } else {
        this.pageBottom = true;
      }
    },
    urlHandle(v) {
      let data = {
        articleContent: v.articleContent,
        articleNo: v.articleNo,
        noticeType: 6,
        index: 2,
      };
      uni.navigateTo({
        url: `/guideInfo/workList/workDetail?data=${encodeURIComponent(
          JSON.stringify(data)
        )}`,
      });
    },
    getList() {
      let data = {
        id: this.options.id,
        noticeType: 6,
        pageNo: this.pageConfig.pageNo,
        pageSize: this.pageConfig.pageSize,
      };

      homePageDetail(data).then((res) => {
        this.dataSource = this.dataSource.concat(res.result.records || []);
        this.pageConfig.total = res.result.total;
      });
    },
  },
};
</script>

<style lang="scss">
.lawsAndRegulations {
  height: 100%;
  .wrapper-content {
    background: #f9f9f9;
    height: 100%;
    padding: 24rpx 20rpx;
    .wrapper-item {
      padding: 30rpx;
      background: #ffffff;
      border-bottom: 1px solid #dedcdc;

      .itemList {
        display: flex;
        justify-content: space-between;
        font-size: 30rpx;
        .name {
          min-width: 600rpx;
          font-family: PingFang SC;
          font-weight: bold;
        }
      }
    }
  }
}
</style>
